package com.frx.leetoffer.link;

import com.frx.chaptertwo.Array;

import java.util.ArrayList;

/**
 * @author ：frx
 * @date ：Created in 2019/11/17 22:35
 * @description：ToDO
 * @modified By：
 * @version: ToDO
 */
public class LinkReverse {

    public static void main(String[] args){
        ListNode node1 = new ListNode(1);
        ListNode node2 = new ListNode(2);
        ListNode node3 = new ListNode(3);
        node1.next = node2;
        node2.next = node3;
        System.out.println(solution(node1));
    }

    public static ArrayList<Integer> solution(ListNode node){
        ArrayList<Integer> result = new ArrayList<>();
        ListNode head = new ListNode(0);
        head.next = node;
        ListNode cur = head.next;
        while (cur != null){
            ListNode next = cur.next;
            cur.next = head;
            head = cur;
            cur = next;
        }
        node.next = null;
        while (head != null){
            result.add(head.val);
            head = head.next;
        }
        return result;
    }

    static class ListNode{
        int val;
        ListNode next;
        ListNode(int val){
            this.val = val;
        }
    }
}
